#include "rightclick.h"
#include <QMouseEvent>
#include <QMenu>
#include <QMessageBox>
#include "addnewevent.h"
#include "editwindow.h"

RightClick::RightClick(EventsHandler *events) : envts(events)
{
    //mainWindow = parent;
    //installEventFilter(this);
    //QMessageBox::warning(this,"b",selectedDate.toString());
}

bool RightClick::eventFilter(QObject *obj, QEvent *event)
{
    if(event->type() == QEvent::ContextMenu)
    {
        //QDate date = QCalendarWidget::selectedDate();

        QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
        QMenu *menu = new QMenu(this);

        QAction *newButton = new QAction("New",this);
        menu->addAction(newButton);
        connect(newButton, SIGNAL(triggered()),this,SLOT(clickedNew()));

        QAction *editButton = new QAction("Edit",this);
        menu->addAction(editButton);
        connect(editButton, SIGNAL(triggered()),this,SLOT(clickedEdit()));
        menu->exec(mouseEvent->globalPos());

        return false;
    }
    else
        return QCalendarWidget::eventFilter(obj, event);
}

void RightClick::clickedNew()
{
    AddNewEvent *naujas = new AddNewEvent(selectedDate,envts);
    naujas->show();
    //QMessageBox::warning(this,"Hello World", "You've clicked NEW!");
}

void RightClick::clickedEdit()
{
    EditWindow *naujas = new EditWindow(selectedDate,envts);
    naujas->show();
    //QMessageBox::warning(this,"Hello World", "You've clicked EDIT!");
}

void RightClick::setDate(QDate date)
{
    selectedDate = date;
}
